package com.xqboss.web.controller.market;

import com.xqboss.apps.dto.market.MarketBoxInfoDto;
import com.xqboss.apps.dto.market.MarketOffShelfDto;
import com.xqboss.apps.dto.market.MarketResellDto;
import com.xqboss.apps.service.market.MarketService;
import com.xqboss.apps.vo.market.MarketResellBoxInfoVo;
import com.xqboss.apps.vo.market.WebMarketResellBoxInfoVo;
import com.xqboss.common.annotation.Log;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@Api(tags = "市场")
@RestController
@RequestMapping("/web/market")
public class WebMarketController extends BaseController {
    @Autowired
    private MarketService marketService;

    @PreAuthorize("@ss.hasPermi('web:market:list')")
    @ApiOperation("转卖记录(典藏、装备、宝盒、材料)")
    @GetMapping("list")
    public R resellRecord(@Validated MarketResellDto dto) {
        switch (dto.getStatus()) {
            case TRADING:
            case CANCEL:
                return marketService.resellRecord(dto, dto.getUserId());

            case SOLD_OUT:
            case TRADE:
                return marketService.resellRecord2(dto, dto.getUserId());

            default:
                return R.fail("市场状态错误");
        }
    }

    @PreAuthorize("@ss.hasPermi('web:market:info')")
    @ApiOperation("转卖记录(宝盒、材料)详情")
    @GetMapping("box-info")
    public R<List<WebMarketResellBoxInfoVo>> resellRecordBoxInfo(@Validated MarketBoxInfoDto dto) {
        return marketService.webResellRecordBoxInfo(dto, dto.getUserId());
    }


    @Log(title = "下架市场转卖", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('web:market:off-shelf')")
    @ApiOperation("下架市场转卖")
    @PostMapping("off-shelf")
    public R offShelf(@Validated @RequestBody MarketOffShelfDto dto) {
        marketService.offShelf(dto.getMarketType(), dto.getSourceId());
        return R.ok();
    }
}
